package com.zg.indiv.web;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zg.common.core.R;
import com.zg.common.core.dao.indiv.entity.IndivDataType;
import com.zg.indiv.domain.req.dataType.*;
import com.zg.indiv.domain.vo.IndivDataTypeVo;
import com.zg.indiv.service.IndivDataTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author lixin
 */
@Api(tags = {"数据类型管理"})
@RestController
@RequiredArgsConstructor
public class IndivDataTypeController {
    private final IndivDataTypeService indivDataTypeService;

    @ApiOperation("分页查询数据类型")
    @PostMapping("/dataType/page")
    public R<IPage<IndivDataTypeVo>> page(@RequestBody @Valid IndivDataTypePageReq param) {
        IPage<IndivDataType> page = indivDataTypeService.page(param);
        IPage<IndivDataTypeVo> result = new Page<>();
        BeanUtil.copyProperties(page, result);
        return R.success(result);
    }

    @ApiOperation("新增数据类型")
    @ApiResponses({
            @ApiResponse(code = 809002002, message = "请选择正确的目录"),
            @ApiResponse(code = 809003001, message = "数据类型名称已被使用"),
            @ApiResponse(code = 809003002, message = "请选择正确的表单"),
            @ApiResponse(code = 809003003, message = "请选择正确的文件类型"),
            @ApiResponse(code = 809003004, message = "请选择正确的类型")
    })
    @PostMapping("/dataType/add")
    public R<Void> add(@RequestBody @Valid IndivDataTypeAddReq param) {
        indivDataTypeService.add(param);
        return R.success();
    }

    @ApiOperation("修改数据类型")
    @ApiResponses({
            @ApiResponse(code = 809003005, message = "请选择正确的数据类型"),
            @ApiResponse(code = 809003001, message = "数据类型名称已被使用"),
            @ApiResponse(code = 809003002, message = "请选择正确的表单"),
            @ApiResponse(code = 809003003, message = "请选择正确的文件类型"),
            @ApiResponse(code = 809003004, message = "请选择正确的类型")
    })
    @PostMapping("/dataType/edit")
    public R<Void> edit(@RequestBody @Valid IndivDataTypeEditReq param) {
        indivDataTypeService.edit(param);
        return R.success();
    }

    @ApiOperation("删除数据类型")
    @PostMapping("/dataType/remove")
    public R<Void> remove(@RequestBody List<Long> idList) {
        indivDataTypeService.remove(idList);
        return R.success();
    }
}
